﻿using HR.Config;
using HR.Filters;
using HR.IService;
using HR.Models;
using Microsoft.AspNetCore.Mvc;

namespace HR.Controllers
{
    /// <summary>
    /// 职位分类设置和职位设置控制器
    /// </summary>
    public class PositionSetController : Controller
    {
        private readonly IConfig_majorKindService icmks;
        private readonly IConfig_MajorService icms;

        public PositionSetController(IConfig_majorKindService icmks, IConfig_MajorService icms)
        {
            this.icmks = icmks;
            this.icms = icms;
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        public IActionResult PositionClassSet()
        {
            return View();
        }
        [HttpGet]
        public async Task<IActionResult> CMKOnPageFill()
        {
            List<config_major_kind> list = await icmks.CMKOnPageFill();
            return Json(list);
        }
        /// <summary>
        /// 职位分类设置分页
        /// </summary>
        /// <param name="pgsize"></param>
        /// <param name="pgcurrent"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> PositionClassFill(int pgsize,int pgcurrent)
        {
            Paging<config_major_kind> pg =await icmks.CMajorKindFill(pgsize,pgcurrent);
            return Json(pg);
        }
        [HttpPost]
        public async Task<IActionResult> PositionClassAdd([FromBody] config_major_kind cmk)
        {
            int res = await icmks.CMajorKindAdd(cmk);
            return Json(res);
        }
        [HttpPost]
        public async Task<IActionResult> PositionClassUpdate([FromBody] config_major_kind cmk)
        {
            int res = await icmks.CMajorKindUpdate(cmk);
            return Json(res);
        }
        [HttpDelete]
        public async Task<IActionResult> PositionClassDelete(short mfk_id)
        {
            int res = await icmks.CMajorKIndDelete(mfk_id);
            return Json(res);
        }
        /// <summary>
        /// 职位设置
        /// </summary>
        /// <returns></returns>
        [TypeFilter(typeof(RoleFilterAttribute))]
        [HttpGet]
        public IActionResult PositionConfig()
        {
            return View();
        }
        [HttpGet]
        public async Task<IActionResult> PositionConfigFill(int pgsize,int pgcurrent)
        {
            Paging<config_major> pg = await icms.CMajorFill(pgsize, pgcurrent);
            return Json(pg);
        }
        [HttpGet]
        public async Task<IActionResult> PositionClassFill1()
        {
            List<config_major_kind> list = await icms.CMKindsFill();
            return Json(list);
        }
        [HttpPost]
        public async Task<IActionResult> PositionConfigAdd([FromBody] config_major cm)
        {
            int res = await icms.CMajorAdd(cm);
            return Json(res);
        }
        [HttpPost]
        public async Task<IActionResult> PositionConfigUpdate([FromBody] config_major cm)
        {
            int res = await icms.CMajorUpdate(cm);
            return Json(res);
        }
        [HttpDelete]
        public async Task<IActionResult> PositionConfigDelete(short mak_id)
        {
            int res = await icms.CMajorDelete(mak_id);
            return Json(res);
        }
    }
}
